<template>
  <div class="mod-config">
    <el-card>
      <el-tabs value="first">
        <el-tab-pane label="项目信息" name="first">
          <el-form size="small" label-width="170px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="项目编号：" prop="projectCode">
                  <label>HNZB2020-05-0103</label>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目名称：" prop="projectName">
                  <label>测试项目名称</label>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="当前标段(包)编号" prop="tradeTypeName">
                  <label>HNZB2020-05-0103/01</label>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="当前标段(包)名称" prop="projectTypeOneName">
                  <label>测试项目名称包段</label>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <el-card class="search-box">
      <div slot="header" class="clearfix">
        <span>查询条件</span>
        <el-button @click="showAdvanced"
                   v-bind:class="[searchBox.advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down','advanced']" type="text">展开高级查询</el-button>
      </div>
      <div>
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
          <el-form-item>
            <el-input v-model="dataForm.code" size="small" placeholder="路勘公告名称" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.key"  size="small"  placeholder="联系人" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.key" size="small"  placeholder="状态" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.key" size="small"  placeholder="标段(包)名称" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()" icon="el-icon-search" size="small" >查询</el-button>
          </el-form-item>
          <div class="advanced-box" v-show="searchBox.advanced">
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </el-card>
    <el-card class="data-box">
      <div slot="header" class="clearfix">
        <div class="button-box">
          <div>
            <el-button size="mini" class="el-button--black" @click="getDataList()" icon="el-icon-refresh"></el-button>
            <el-button size="mini" type="primary" @click="addOrUpdateHandle()">查看退款记录</el-button>
          </div>
          <div>
            <el-button-group>
              <el-dropdown :hide-on-click="false">
                <el-button size="mini" icon="el-icon-arrow-down el-icon--right">列</el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="field in defaultFormThead">
                    <el-checkbox label="field.field" v-model="field.checked" @change="checkboxVal($event,field.field)">{{ field.label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-button size="mini" v-if="isAuth('bid:question:save')" icon="el-icon-s-unfold" @click="addOrUpdateHandle()">导出</el-button>
            </el-button-group>
          </div>
        </div>
      </div>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column
          prop="id"
          header-align="center"
          align="center"
          label="序号">
        </el-table-column>
        <el-table-column
          prop="projectId"
          header-align="center"
          align="center"
          label="投标人">
        </el-table-column>
        <el-table-column
          prop="company"
          header-align="center"
          align="center"
          label="标段可用余额">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="退款锁定金额">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="本次退款金额">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="退款账号户名">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="退款账号">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="退款账号开户行">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="退款银行号">
        </el-table-column>
        <el-table-column
          prop="contacter"
          header-align="center"
          align="center"
          label="备注">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
            <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>
    <el-card>
      <div style="text-align: center;">
        <el-button size="small" type="primary" @click="dataFormSubmit()">保存</el-button>
        <el-button size="small" type="primary" @click="dataFormSubmit()">提交审批</el-button>
        <el-button size="small" @click="$router.go(-1)">返回</el-button>
      </div>
    </el-card>

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './enrol-add-or-update'
  export default {
    data () {
      return {
        searchBox: {
          advanced: false
        },
        dataForm: {
          code: '',
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bid/enrol/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.$router.push({
          path: '/bid/depositrefund-list'
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/bid/enrol/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },

      // 切换高级查询
      showAdvanced () {
        this.searchBox.advanced = !this.searchBox.advanced
      }
    }
  }
</script>
